package com.glory.brepda.activity.mfg;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.glory.brepda.R;
import com.glory.brepda.adapter.DefectListAdapter;
import com.glory.brepda.adapter.EDCListAdapter;
import com.glory.brepda.base.BaseActivity;
import com.glory.brepda.base.MyApp;
import com.glory.brepda.callback.CustomDialogEntityCallBack;
import com.glory.brepda.entity.DefectCodeEntity;
import com.glory.brepda.entity.EDCListBean;
import com.glory.brepda.entity.LotInfoEntity;
import com.glory.brepda.entity.LotLists;
import com.glory.brepda.entity.LotactionLists;
import com.glory.brepda.entity.ScrapEntity;
import com.glory.brepda.entity.response.BaseResponseBean;
import com.glory.brepda.utils.LotUtils;
import com.glory.brepda.utils.NetUtils;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.Response;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_DialogEntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.dialog.FreeUI_GeneralFragmentDialog;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_DialogUtils;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_LogUtils;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_ToastUtils;

import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;

import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.RecyclerView;

import org.apache.commons.lang3.StringUtils;

import butterknife.BindView;
import butterknife.OnClick;

public class WBWorkEnd2Activity extends BaseActivity {

    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.tvBaseSubmit)
    TextView tvBaseSubmit;
    @BindView(R.id.llMain)
    LinearLayout llMain;
    @BindView(R.id.llDefectList)
    LinearLayout llDefectList;
    @BindView(R.id.rvDefectList)
    RecyclerView rvDefectList;
    @BindView(R.id.rvEdcDataList)
    RecyclerView rvEdcDataList;
    @BindView(R.id.tvDefectNum)
    TextView tvDefectNum;
    @BindView(R.id.llEap)
    LinearLayout llEap;
    @BindView(R.id.rlEap)
    RelativeLayout rlEap;
    private DefectListAdapter defectListAdapter;
    private EDCListAdapter edcListAdapter;
    private String lotID;
    private String eqpID;
    private String scrapCodeSRCNUM;
    private String defectCode;
    private String trackOutNum;
    private List<String> list;
    private LotInfoEntity lotInfoEntity;
    private List<ScrapEntity> scrapList;
    private String method;
    private String title;
    private String scan;
    private String thinning = "";
    private String totalNumber = "";
    private String activity;
    private String TRACKOUTQTY = "";
    private String aMatCount = "";
    private String tMatCount = "";

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_work_end_wb2;
    }

    @Override
    protected void initView() {
        setMainLayout(llMain);
        llDefectList.setVisibility(View.GONE);
        initRecyclerView(rvEdcDataList, this);
        initRecyclerView(rvDefectList, this);
        Bundle bundle = getIntent().getExtras();
        lotInfoEntity = (LotInfoEntity) bundle.getSerializable("LOTINFOENTITY");
        scrapList = (List<ScrapEntity>) bundle.getSerializable("ScrapList");

        list = bundle.getStringArrayList("MATERIELMODELLIST");
        lotID = bundle.getString("LOTID");
        eqpID = bundle.getString("EQPID");
        method = bundle.getString("method");
        title = bundle.getString("title");
        scan = bundle.getString("scan");
        thinning = bundle.getString("THINNING");
        totalNumber = bundle.getString("TOTALNUMBER");
        activity = bundle.getString("activity");
        TRACKOUTQTY = bundle.getString("TRACKOUTQTY");
        aMatCount = bundle.getString("aMatCount");
        tMatCount = bundle.getString("tMatCount");
        scan = scan == null ? "" : scan;
        tvTitle.setText(title);
        scrapCodeSRCNUM = bundle.getString("SCRAPCODESRC");
        defectCode = bundle.getString("DEFECTCODE");
        trackOutNum = bundle.getString("TRACKOUTNUM");
        defectListAdapter = new DefectListAdapter(null, tvDefectNum, true);
        defectListAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
        defectListAdapter.isFirstOnly(true);
        rvDefectList.setAdapter(defectListAdapter);
        defectListAdapter.setTotalNum(Integer.parseInt(lotInfoEntity.getLOT().getMAINQTY()));
        defectListAdapter.setListener(new DefectListAdapter.onListener() {
            @Override
            public void OnListener(String s, ScrapEntity item) {
                try {
                    item.setMAINQTY(s);
                    item.setSUBQTY(s);
                    ScrapEntity.MainQTY mainQTY = new ScrapEntity.MainQTY(s);
                    List<ScrapEntity.MainQTY> data = new ArrayList<>();
                    data.add(mainQTY);
                    item.setQTYLIST(data);
                    long num = defectListAdapter.Calculation();
                    if (num < 0) {
                        FreeApi_ToastUtils.showFreeToast("不良数量大于批次数量，请重新输入", MyApp.app, false, Toast.LENGTH_LONG);
                        item.setMAINQTY("0");
                        item.setSUBQTY("0");
                        ScrapEntity.MainQTY mainQTY1 = new ScrapEntity.MainQTY("0");
                        List<ScrapEntity.MainQTY> data1 = new ArrayList<>();
                        data.add(mainQTY1);
                        item.setQTYLIST(data1);
                        tvDefectNum.setText("0");
                    }else {
                        tvDefectNum.setText(num + "");
                    }

                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            }
        });

        getDefectInfo();
        if (method.equals("GENERALLOTTRACKOUT")){
            rlEap.setVisibility(View.GONE);
            llEap.setVisibility(View.GONE);
            rvEdcDataList.setVisibility(View.GONE);
        }else {
            getEdcData();
        }
        edcListAdapter = new EDCListAdapter(null);
        edcListAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
        edcListAdapter.isFirstOnly(true);
        rvEdcDataList.setAdapter(edcListAdapter);
    }

    @Override
    protected void initData() {

    }

    @OnClick({R.id.tvBaseSubmit, R.id.tvGetEDCData})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tvBaseSubmit:

                int sumDefect = 0;
                if (defectListAdapter.getData() != null) {
                    for (ScrapEntity entity : defectListAdapter.getData()) {
                        sumDefect += Integer.parseInt(entity.getMAINQTY().equals("") ? "0" : entity.getMAINQTY());
                    }
                } else {
                    sumDefect += 0;
                }
                tvDefectNum.setText(sumDefect + "");
                String defectNum = tvDefectNum.getText().toString().equals("") ? "0" : tvDefectNum.getText().toString();
                int defect = Integer.parseInt(defectNum) + Integer.parseInt(trackOutNum) + Integer.parseInt(scrapCodeSRCNUM);

//                if (defect != Integer.parseInt(lotInfoEntity.getLOT().getMAINQTY())) {
//                    showToast("报废数量输入不正确", false);
//                    return;
//                }
//                WBLOTTRACKOUT
                lotDAWBTrackOut(
                        this,
                        method,
                        getSupportFragmentManager(),
                        "",
                        eqpID,
                        lotID,
                        defectListAdapter.getData(),
                        list,
                        defectCode,
                        lotInfoEntity.getLOT().getMAINQTY(),
                        lotInfoEntity,
                        tvDefectNum.getText().toString().equals("") ? Integer.parseInt(scrapCodeSRCNUM) : Integer.parseInt(tvDefectNum.getText().toString()) + Integer.parseInt(scrapCodeSRCNUM),
                        trackOutNum,
                        edcListAdapter.getData(),
                        new LotUtils.netCallback() {
                            @Override
                            public void onSuccess(Object response) {

                                Intent intent = new Intent();
                                setResult(1, intent);
                                finish();
                            }

                            @Override
                            public void onFail(Throwable t) {
                                if (!tvDefectNum.getText().toString().equals("")) {
                                    int defectNum = Integer.parseInt(tvDefectNum.getText().toString());
                                }
                            }
                        });
                break;
            case R.id.tvGetEDCData:
                FreeUI_EntityCallBack<BaseResponseBean<EDCListBean>> callBack = new CustomDialogEntityCallBack<BaseResponseBean<EDCListBean>>
                        (new TypeToken<BaseResponseBean<EDCListBean>>() {
                        }.getType(), getSupportFragmentManager(), this) {

                    @Override
                    public void onSuccess(Response<BaseResponseBean<EDCListBean>> response) {
                        super.onSuccess(response);
                        if (response.body().isSuccess(WBWorkEnd2Activity.this, false, getSupportFragmentManager())) {
                            edcListAdapter.setNewData(response.body().getResponse().getBody().getList());
                            for (EDCListBean.ListBean edcList : response.body().getResponse().getBody().getList()) {
                                for (ScrapEntity defectList : defectListAdapter.getData()) {
                                    if (edcList.getName().equals(defectList.getACTIONCODE())) {
                                        defectList.setMAINQTY(edcList.getValue());
                                    }
                                }
                            }
                            defectListAdapter.notifyDataSetChanged();

                            int sum = 0;
                            for (ScrapEntity entity : defectListAdapter.getData()) {
                                sum += Integer.parseInt(entity.getMAINQTY());
                            }
                            tvDefectNum.setText(sum + "");

                        }
                    }

                    @Override
                    public void onError(Response<BaseResponseBean<EDCListBean>> response) {
                        super.onError(response);
                        FreeApi_LogUtils.saveErrorMessages(response.getException(), "TrackOutEDC");
                        FreeApi_ToastUtils.showFreeToast("连接服务器失败", WBWorkEnd2Activity.this, false, 0);
                    }
                };
                JsonObject map = new JsonObject();
                map.addProperty("EQUIPMENTID", eqpID);
                map.addProperty("LOTID", lotID);
                NetUtils.requestPostNet("TrackOutEDC", "TrackOutEDC", WBWorkEnd2Activity.this, map, callBack);
                break;
        }
    }

    private void getDefectInfo() {

        FreeUI_EntityCallBack<BaseResponseBean<DefectCodeEntity>> callback = new FreeUI_DialogEntityCallBack<BaseResponseBean<DefectCodeEntity>>
                (new TypeToken<BaseResponseBean<DefectCodeEntity>>() {
                }.getType(), getSupportFragmentManager(), this) {

            @Override
            public void onSuccess(Response<BaseResponseBean<DefectCodeEntity>> response) {
                super.onSuccess(response);
                if (response.body().isSuccess(getApplicationContext(), true, getSupportFragmentManager())) {
                    List<DefectCodeEntity.DefectCode> scrapcodelists = response.body().getResponse().getBody().getADREFLIST();
                    for (DefectCodeEntity.DefectCode code : scrapcodelists) {
                        ScrapEntity scrapEntity = new ScrapEntity();
                        scrapEntity.setACTIONCODE(code.getKEY());
                        scrapEntity.setACTIONREASON(code.getDESCRIPTION());
                        scrapEntity.setLOTID(lotInfoEntity.getLOT().getLOTID());
                        scrapEntity.setLOTRRN(lotInfoEntity.getLOT().getOBJECTRRN());
                        scrapEntity.setACTIONTYPE("Scrap");
                        scrapEntity.setSUBQTY(lotInfoEntity.getLOT().getMAINQTY() + "");

                        if (defectListAdapter.getData().size() > 0) {
                            if (containCode(scrapEntity)) {
                                defectListAdapter.addData(scrapEntity);
                            }
                        } else {
                            defectListAdapter.addData(scrapEntity);
                        }
                        if (defectListAdapter.getData().size() > 0) {
                            int sum = 0;
                            for (ScrapEntity entity : defectListAdapter.getData()) {
                                sum += Integer.parseInt(entity.getMAINQTY().equals("") ? "0" : entity.getMAINQTY());
                            }
                            tvDefectNum.setText(sum + "");
                        }
                    }
                }
            }

            @Override
            public void onError(Response<BaseResponseBean<DefectCodeEntity>> response) {
                super.onError(response);
                loadError(response.getException(), "GETSTEPBYLOT");
            }
        };
        JsonObject map = new JsonObject();
        map.addProperty("REFERENCENAME", lotInfoEntity.getSTEPLIST().get(0).getDEFECTCODESRC());
//        map.add("REFERENCETYPE", new JsonParser().parse(new Gson().toJson(new LotList(s))).getAsJsonObject());//传批次集合
        map.addProperty("REFERENCETYPE", "USER");
        NetUtils.requestPostNet("IF.ADREFLISTQUERY", "Common", WBWorkEnd2Activity.this, map, callback);
    }

    private void lotDAWBTrackOut(Activity context,
                                 String method,
                                 FragmentManager fragmentManager,
                                 String storageid,
                                 String eqpWork,
                                 String lotID,
                                 List<ScrapEntity> defectData,
                                 List<String> carrierList,
                                 String scrapNum,
                                 String subqty,
                                 LotInfoEntity lotInfoEntity,
                                 int defectNum,
                                 String trackNum,
                                 List<EDCListBean.ListBean> edcList,
                                 LotUtils.netCallback callback) {

        FreeUI_GeneralFragmentDialog freeU_generalFragmentDialog = new FreeUI_GeneralFragmentDialog();
        View view = LayoutInflater.from(context.getApplicationContext()).inflate(R.layout.dialog_trackout, null);
        TextView tvLotID = view.findViewById(R.id.tvLotID);
        TextView tvScrapNum = view.findViewById(R.id.tvScrapNum);
        TextView tvTotalNum = view.findViewById(R.id.tvTotalNum);
        TextView tvaMatCount = view.findViewById(R.id.tvaMatCount);
        TextView tvtMatCount = view.findViewById(R.id.tvtMatCount);
        tvaMatCount.setText(aMatCount);
        tvtMatCount.setText(tMatCount);
        tvScrapNum.setText(scrapNum);
        tvLotID.setText(lotID);
        TextView tvStep = view.findViewById(R.id.tvStep);
        tvStep.setText(lotInfoEntity.getLOT().getSTEPNAME() + "/" + lotInfoEntity.getLOT().getSTEPDESC());
        TextView tvEqpID = view.findViewById(R.id.tvEqpID);
        tvEqpID.setText(eqpWork);
        TextView tvTrackInQTY = view.findViewById(R.id.tvTrackInQTY);
        tvTrackInQTY.setText(subqty);
        TextView tvTrackOutQTY = view.findViewById(R.id.tvTrackOutQTY);
        int mSubqty = Integer.parseInt(subqty);
        int scrapInt = Integer.parseInt(scrapNum.equals("") ? "0" : scrapNum);

        TextView tvDefectNum = view.findViewById(R.id.tvDefectNum);
        TextView tvDefect = view.findViewById(R.id.tvDefect);
        NumberFormat numberFormat = NumberFormat.getInstance();
        numberFormat.setMaximumFractionDigits(2);
        int sumDefect = 0;
        if (defectData != null) {
            for (ScrapEntity entity : defectData) {
                if (!entity.getACTIONREASON().contains("不记录良率")) {
                    sumDefect += Integer.parseInt(entity.getMAINQTY().equals("") ? "0" : entity.getMAINQTY());
                }
            }
        } else {
            sumDefect += 0;
        }
//        tvTrackOutQTY.setText(String.valueOf(mSubqty - sumDefect - scrapInt));
        tvTrackOutQTY.setText(trackNum);

        tvTotalNum.setText(String.valueOf(scrapInt + sumDefect));
        tvDefectNum.setText(String.valueOf(sumDefect));
//        String result = numberFormat.format(((float) (mainQTY - sumDefect) / (float) mainQTY) * 100);
//        String result = numberFormat.format(((float) (Integer.parseInt(tvTrackOutQTY.getText().toString())) / (float) mSubqty) * 100);
//        BigDecimal b1 = new BigDecimal(Double.toString(Long.parseLong(tvTrackOutQTY.getText().toString())));
        BigDecimal b2 = new BigDecimal(Double.toString(mSubqty));
        BigDecimal b1 = new BigDecimal(Double.toString(Integer.parseInt(tvTrackOutQTY.getText().toString())));
        double v1 = b1.divide(b2, 5, BigDecimal.ROUND_HALF_UP).doubleValue();
        double v2 = v1 * 100;
        tvDefect.setText(v2 + "%");

        TextView tvCancel = view.findViewById(R.id.tvCancel);
        TextView tvConfirm = view.findViewById(R.id.tvConfirm);
        tvCancel.setOnClickListener(view1 -> {
            freeU_generalFragmentDialog.dismiss();
        });
        tvConfirm.setOnClickListener(v -> {
            FreeUI_EntityCallBack<BaseResponseBean<LotInfoEntity>> callBack = new CustomDialogEntityCallBack<BaseResponseBean<LotInfoEntity>>
                    (new TypeToken<BaseResponseBean<LotInfoEntity>>() {
                    }.getType(), fragmentManager, context) {

                @Override
                public void onSuccess(Response<BaseResponseBean<LotInfoEntity>> response) {
                    super.onSuccess(response);
                    if (response.body().isSuccess(context, false, fragmentManager)) {
                        String holdstate = response.body().getResponse().getBody().getLOTLIST().get(0).getHOLDSTATE();
                        FreeApi_DialogUtils.getConfirmDialog(context, "确定", holdstate.equals("On") ? "该批次良率超标！" : "出站成功", () -> {
                            callback.onSuccess("");
                        }).show(fragmentManager, "CONFIRM_DIALOG");
                    }
                }

                @Override
                public void onError(Response<BaseResponseBean<LotInfoEntity>> response) {
                    super.onError(response);
                    FreeApi_LogUtils.saveErrorMessages(response.getException(), "LOTTRACKOUT");
                    FreeApi_ToastUtils.showFreeToast("连接服务器失败", context, false, 0);
                }
            };
            JsonObject map = new JsonObject();
//            String url = "";
//            if (method.equals("Common")){
//                url = "InspectErrorTrackOut";
//            }else if (method.equals("GENERALLOTTRACKOUT")){
//                url = "MultiEqpNoNumTrackIn";
//            }else {
//                url = "DefaultTrackOut";
//            }
//            map.addProperty("ACTIONTYPE", url);

            String messageName = "IF.LOTTRACKOUT";
            String actiontype = "DefaultTrackOut";

            switch (method) {
                case "MULTIDEVICELOTTRACKOUT":
                    map.addProperty("TYPE", "1");
                    break;
                case "MultiMasterTrackOut":
                case "Common":
                    messageName = "IF.MULTIMASTERLOTTRACKOUT";
                    actiontype = "MultiMasterTrackOut";
                    break;
            }
            if (activity != null && activity.equals("MultiEqpTrackOutActivity")) {
                map.addProperty("TYPE", "0");
                map.addProperty("TRACK_OUT_QTY", TRACKOUTQTY);
            }
            map.addProperty("ACTIONTYPE", actiontype);
            map.addProperty("EQUIPMENTID", eqpWork);
            map.addProperty("THINNINGTHICKNESS", thinning);
            map.addProperty("OUTOVERTOTALNUMBER", totalNumber);
            map.addProperty("CARRIERACTION", "");
            map.addProperty("DURABLE", "");
            map.addProperty("ALLREWORKFLAG", "N");
            map.addProperty("WAREHOUSEID", scrapNum);
            map.addProperty("STORAGEID", storageid);
            map.addProperty("SPC2", lotInfoEntity.getPART().getSPEC2());
            map.addProperty("aMatCount", aMatCount);
            List<LotLists> lotList = new ArrayList<>();
            List<LotactionLists> lotactionList = new ArrayList<>();
//            LotLists lotList1 = new LotLists(lotID, scan.equals("") ? lotInfoEntity.getLOT().getMAINQTY() : scan);
            double v3 = Double.parseDouble(trackNum) + Double.parseDouble(scrapNum);
            LotLists lotList1;
            // 25/7/15 901713 使用method进行识别批次用什么方式出站。DA和组合设备出站只传出站数量，其他【一般出站和多设备出站】传出站数量+报废数量
            // 通过method进行识别，MultiMasterTrackOut 组合设备出站识别代码，DBLOTTRACKOUT，DA出站识别代码
            // 只有这两个代码走新逻辑，即只传出站数量，不传出站数量+报废数
            if (StringUtils.equals(method, "MultiMasterTrackOut") || StringUtils.equals(method, "DBLOTTRACKOUT")) {
                lotList1 = new LotLists(lotID, trackNum);
            } else {
                // 其他识别代码：一般出站和多设备出站走回原来的逻辑
                lotList1 = new LotLists(lotID, String.valueOf(v3));
            }
            lotList.add(lotList1);

            if (defectData != null) {
                for (ScrapEntity mDefectData : defectData) {
                    ArrayList<LotactionLists.QTYList> qtyList = new ArrayList<>();
                    LotactionLists.QTYList qtybean = new LotactionLists.QTYList();

                    qtybean.setSUBQTY("0");
                    qtybean.setMAINQTY(mDefectData.getMAINQTY());
                    qtyList.add(qtybean);

//                    LotactionLists lotactionLists = new LotactionLists(lotID,
//                            mDefectData.getACTIONCODE(),
//                            mDefectData.getACTIONREASON(),
//                            method.equals("Common") ? mDefectData.getMAINQTY() : "0",
//                            method.equals("Common") ? "0" : mDefectData.getMAINQTY(),
//                            qtyList);

                    if (!mDefectData.getMAINQTY().equals("0")){
                        LotactionLists lotactionLists1 = new LotactionLists();
                        lotactionLists1.setLOTID(lotID);
                        lotactionLists1.setACTIONCODE(mDefectData.getACTIONCODE());
                        lotactionLists1.setACTIONREASON(mDefectData.getACTIONREASON());
                        lotactionLists1.setACTIONTYPE("Defect");
                        lotactionLists1.setSUBQTY(mDefectData.getSUBQTY());
                        lotactionLists1.setMAINQTY(mDefectData.getMAINQTY());
                        lotactionLists1.setQTYLIST(qtyList);

                        lotactionList.add(lotactionLists1);
                    }
                }
            }
            if (scrapList != null) {
                for (ScrapEntity mDefectData : scrapList) {
                    ArrayList<LotactionLists.QTYList> qtyList = new ArrayList<>();
                    LotactionLists.QTYList qtybean = new LotactionLists.QTYList();

                    qtybean.setSUBQTY("0");
                    qtybean.setMAINQTY(mDefectData.getMAINQTY());
                    qtyList.add(qtybean);

                    if (!(mDefectData.getMAINQTY().equals("0"))){

                        LotactionLists lotactionLists1 = new LotactionLists();
                        lotactionLists1.setLOTID(lotID);
                        lotactionLists1.setACTIONCODE(mDefectData.getACTIONCODE());
                        lotactionLists1.setACTIONREASON(mDefectData.getACTIONREASON());
                        lotactionLists1.setACTIONTYPE("Scrap");
                        lotactionLists1.setSUBQTY(mDefectData.getSUBQTY());
                        lotactionLists1.setMAINQTY(mDefectData.getMAINQTY());
                        lotactionLists1.setQTYLIST(qtyList);

                        lotactionList.add(lotactionLists1);
                    }
                }
            }

            map.add("LOTLIST", new JsonParser().parse(new Gson().toJson(lotList)).getAsJsonArray());//传批次集合
            map.add("LOTACTIONLIST", new JsonParser().parse(new Gson().toJson(lotactionList)).getAsJsonArray());
            map.add("DURABLEIDLIST", new JsonParser().parse(new Gson().toJson(carrierList)).getAsJsonArray());
            if (edcList != null) {
                map.add("EDCLIST", new JsonParser().parse(new Gson().toJson(edcList)).getAsJsonArray());
            }
            NetUtils.requestPostNet(messageName, method, context, map, callBack);
            freeU_generalFragmentDialog.dismiss();
        });

        freeU_generalFragmentDialog.setLayout(view);
        freeU_generalFragmentDialog.show(fragmentManager, "SUBMIT_DIALOG");

    }

    private boolean containCode(ScrapEntity scrapEntity) {
        for (ScrapEntity bean : defectListAdapter.getData()) {
            if (bean.getACTIONCODE().equals(scrapEntity.getACTIONCODE())) {
                showToast("列表中已有当前不良代码!", false);
                return false;
            }
        }
        return true;
    }
    void getEdcData(){
        FreeUI_EntityCallBack<BaseResponseBean<EDCListBean>> callBack = new CustomDialogEntityCallBack<BaseResponseBean<EDCListBean>>
                (new TypeToken<BaseResponseBean<EDCListBean>>() {
                }.getType(), getSupportFragmentManager(), this) {

            @Override
            public void onSuccess(Response<BaseResponseBean<EDCListBean>> response) {
                super.onSuccess(response);
                if (response.body().isSuccess(WBWorkEnd2Activity.this, false, getSupportFragmentManager())) {
                    edcListAdapter.setNewData(response.body().getResponse().getBody().getList());
                    for (EDCListBean.ListBean edcList : response.body().getResponse().getBody().getList()) {
                        for (ScrapEntity defectList : defectListAdapter.getData()) {
                            if (edcList.getName().equals(defectList.getACTIONCODE())) {
                                defectList.setMAINQTY(edcList.getValue());
                            }
                        }
                    }
                    defectListAdapter.notifyDataSetChanged();

                    int sum = 0;
                    try {
                        for (ScrapEntity entity : defectListAdapter.getData()) {
                            sum += Integer.parseInt(entity.getMAINQTY());
                        }
                    } catch (NumberFormatException e) {
//                        showToast(e.getMessage(),false);
                        FreeApi_ToastUtils.showFreeToast("设备" + eqpID+"离线", WBWorkEnd2Activity.this, false, 0);
                    }


                }
            }

            @Override
            public void onError(Response<BaseResponseBean<EDCListBean>> response) {
                super.onError(response);
                FreeApi_LogUtils.saveErrorMessages(response.getException(), "TrackOutEDC");
                FreeApi_ToastUtils.showFreeToast("连接服务器失败", WBWorkEnd2Activity.this, false, 0);
            }
        };
        JsonObject map = new JsonObject();
        map.addProperty("EQUIPMENTID", eqpID);
        map.addProperty("LOTID", lotID);
        NetUtils.requestPostNet("TrackOutEDC", "TrackOutEDC", WBWorkEnd2Activity.this, map, callBack);

    }
}
